from django.db import models
from django.db.models import SET_NULL

from home.models import cateModel, BannerModel
from user.models import UserModels
from utils.BaseModel import BaseModel


# Create your models here.
class TeacherModel(BaseModel):
    name = models.CharField(max_length=20, verbose_name="教师名称")
    job = models.CharField(max_length=20, verbose_name="教师职称")
    intro = models.TextField(verbose_name="教师简介")
    headimg = models.CharField(max_length=200, verbose_name="教师头像")

    class Meta:
        db_table = "fgteacher"

    def __str__(self):
        return self.name


class CourseModel(BaseModel):
    name = models.CharField(max_length=20, verbose_name="课程名称")
    category = models.ForeignKey(cateModel, on_delete=models.CASCADE, verbose_name="课程分类")
    teacher = models.ForeignKey(TeacherModel, on_delete=models.CASCADE, verbose_name="授课教师")
    intro = models.TextField(verbose_name="课程简介")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="课程价格")
    timeline = models.IntegerField(default=0)
    counts = models.IntegerField(default=0)
    isgood = models.BooleanField(default=False, verbose_name="是否精品")
    ishot = models.BooleanField(default=False, verbose_name="是否为热销")
    ishome = models.BooleanField(default=False, verbose_name="是否推荐到首页广告")
    level = models.IntegerField(choices=((0, "初级"), (1, "中级"), (2, "高级")), default=0)
    cover = models.CharField(max_length=200, verbose_name="课程封面")
    video = models.CharField(max_length=200, verbose_name="课程简介视频")
    score = models.FloatField(default=10.0, verbose_name="评分")

    class Meta:
        db_table = "fgcourse"

    def __str__(self):
        return self.name


class CommModel(BaseModel):
    userCommentsModel = models.ForeignKey(UserModels, on_delete=models.CASCADE, verbose_name="用户ID")
    CommentsModel = models.ForeignKey(CourseModel, on_delete=models.CASCADE, verbose_name="课程ID")
    comments = models.CharField(max_length=200, verbose_name="评价")

    class Meta:
        db_table = "fgcomm"

    def __str__(self):
        return self.comments
